<template>
  <form-item v-bind="item">
    <!-- label 插槽 -->
    <slot v-if="item.type === 'slot'" v-bind="item"></slot>
    <!-- 组件 -->
    <component
      v-else-if="item.type"
      :is="componentName(item.type)"
      :item="item"
      :model="model"
      :global="global"
      v-bind="$attrs"
    >
    </component>
  </form-item>
</template>
<script setup>
import FormItem from './formItem.vue'
import { getCurrentInstance } from 'vue'
const props = defineProps({
  item: Object,
  model: Object,
  global: Object
})

const components = getCurrentInstance().appContext.components
const componentName = (type) => {
  return Object.keys(components).some((name) => name === 'component-' + type) && 'component-' + type
}
</script>
